const {Router,urlencoded,json} = require('express');
const session = require('express-session');
const router = Router();

// 一、引入模块
const goodsRouter = require('./goods');
const userRouter = require('./user');
const vcodeRouter = require('./vcode');
const jwtRouter = require('./jwt');
const uploadRouter = require('./upload');
const cors = require('../filter/cors')

router.use(cors)

// 二、中间件
router.use(urlencoded({extended:false}),json());
// 验证码有效期
router.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true,
    // 设置验证码有效时间
    cookie: { 
        // ms为单位
        maxAge: 1000*60*60*2
     }
}))

// 三、路由
router.use('/goods',goodsRouter);
router.use('/user',userRouter);
router.use('/vcode',vcodeRouter);
router.use('/jwt',jwtRouter);
router.use('/upload',uploadRouter);

module.exports = router;
